#ifndef __UTIL__HPP
#define __UTIL__HPP

#include <time.h>
#include <GL/glew.h>
#include <GLUT/glut.h>
#include <OpenGL/OpenGL.h>
#include <AGL/agl.h>
#include "PBuffer.h"

// error codes
#define  ERROR_GLSL        -1
#define  ERROR_GLEW        -2
#define  ERROR_TEXTURE     -3
#define  ERROR_BINDFBO     -4
#define  ERROR_FBOTEXTURE  -5
#define  ERROR_PARAMS      -6

// struct for variable parts of GL calls (texture format, float format etc)
struct struct_textureParameters {
	char* name;
	GLenum texTarget;
	GLenum texInternalFormat;
	GLenum texFormat;
	char* shader_source;
}; // texture rectangles, texture_float_ARB, RGBA, 32 bits

void initMatPix(bool forceSofwareRenderer);
void compute(int destID, int xTexID, int yTexID, int w, int h, const char* op, int commonLength=0, int xoff=0, int yoff=0, int x=0, int y=0);
void bindTexToFBO(int tex);
void cleanupMatPix();

void initFBO();
void initGLUT();
void initGLEW();
void initCGL();
void initGLSL();
void initPbuffer(int w, int h);

void setActiveShader(const char* op);
void setShader(GLint shader, const char* op);
void setShaderSrc(const char* op, char* source);
void drawQuad(int w, int h);
void setShader(const char* op);
void CGLCheckErr(int err, const char* text);
void checkGLErrors(const char *label);
bool checkFramebufferStatus();
void printProgramInfoLog(GLuint obj);
void printShaderInfoLog(GLuint obj);
void printVector(const float *p, const int N);

extern struct_textureParameters textureParameters;
extern bool usingFBO;

#endif //__UTIL__HPP
